package fr.adfm.ws.SE;

import fr.adfm.paiement.data.ProcessContext;
import fr.adfm.proxy.SE.ExpeditionWS;
import fr.adfm.proxy.SE.ExpeditionWSService;

public class WsExpeditionSE {

	private ProcessContext context;
	private ExpeditionWS ws;
	
	public WsExpeditionSE(ProcessContext context){
		this.context = context;
	}
	
	public void validerStock() {
		context.getContextSE().isStockOK = false;
		
		try {
			openWs();
			String value = ws.validerStock(context.getInput().getIdBonCommande());
			context.getContextSE().isStockOK = value.contains("valid");
		}
		catch(Exception ex) {
			context.setException(ex);
		}
	}
	
	public void annulerBonCommande() {
		try {
			openWs();
			ws.annulerBonCommande(context.getInput().getIdBonCommande());
		}
		catch(Exception ex) {
			context.setException(ex);
		}
	}
	
	public void initialiserEnvoiCommande() {
		try {
			openWs();
			ws.initialiserEnvoiCommande(context.getInput().getIdBonCommande());
		}
		catch(Exception ex) {
			context.setException(ex);
		}
	}
	
	private void openWs() {
		if(ws != null) return;
		
		ExpeditionWSService serv = new ExpeditionWSService();
		ws = serv.getExpeditionWSPort();
	}
}
